package meihua.stopcarapp.ui.adapter;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import meihua.mylibrary.commonutils.TimeUtils;
import meihua.stopcarapp.R;
import meihua.stopcarapp.bean.CouponEntity;

/**
 * Created by Administrator on 2017/5/9.
 */
public class StopCarQuanAdapter extends BaseAdapter {

    private List<CouponEntity> datas;
    private Context context;
    public StopCarQuanAdapter(Context context, List<CouponEntity> datas){
        this.context=context;
        this.datas = datas;
    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver observer) {
        if (observer != null) {
            super.unregisterDataSetObserver(observer);
        }
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView=View.inflate(context, R.layout.item_stop_quan_layout,null);
            holder=new ViewHolder();
            holder.mTimeTxt= (TextView) convertView.findViewById(R.id.item_stop_quan_time);
            holder.mPriceTxt= (TextView) convertView.findViewById(R.id.item_stopcar_price);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.mTimeTxt.setText("有效期至："+ TimeUtils.getTime(Long.parseLong(datas.get(position).getCoupon_utime())));
        holder.mPriceTxt.setText("￥"+datas.get(position).getCoupon_face_value());
        return convertView;
    }
    class ViewHolder{
        TextView mTimeTxt;//有效期
        TextView mPriceTxt;//金额
    }
}
